/*
 * @Author: Starfish_DL
 * @Date: 2020-11-09 21:26:39
 * @LastEditors: Starfish_DL
 * @LastEditTime: 2020-11-09 21:32:05
 * @CurrentVersion: 1.0
 * @Description: 
 */

#include "CStack.h"
#include <iostream>
#include <string>
using namespace std;

cStackLinkNode::cStackLinkNode()
{
    data = '0';
    next = nullptr;
}

cStackLinkNode::~cStackLinkNode()
{
}

cStackLink::cStackLink()
{
    s = new cStackLinkNode();
}

cStackLink::~cStackLink()
{
    cStackLinkNode *pre = s->next, *p = s;
    while (pre != nullptr)
    {
        delete p;
        p = pre;
        pre = pre->next;
    }
    delete p;
}

void cStackLink::Push(char e)
{
    //done function of pushing has finished.
    cStackLinkNode *pre = new cStackLinkNode();
    pre->next = s->next;
    s->next = pre;
    pre->data = e;
}

char cStackLink::Pop()
{
    if (s->next == nullptr)
    {
        return '0';
    }
    cStackLinkNode *p = s->next;
    char e = p->data;
    s->next = p->next;
    delete p;
    return e;
}

char cStackLink::GetTop()
{
    return (s->next->data);
}